<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const canvas = document.createElement("canvas");
      canvas.width = 300;
      canvas.height = 400;
      document.body.append(canvas);
      const ctx = canvas.getContext("2d");
      // 画圆弧
      // arc(x, y, radius, startAngle, endAngle, anticlockwise)
      //   渐变色
      const gradient = ctx.createRadialGradient(120, 200, 50, 120, 200, 100);
      gradient.addColorStop(0, "pink");
      gradient.addColorStop(1, "red");
      ctx.fillStyle = gradient;
      //  画笑脸
      ctx.arc(120, 200, 100, 0, Math.PI * 2, false);
      ctx.lineWidth = 5;
      ctx.stroke();
      ctx.beginPath();
      ctx.strokeStyle = gradient;
      // 画眼睛
      ctx.arc(60, 150, 10, 0, Math.PI * 2, false);
      ctx.stroke();
      ctx.beginPath();
      //   画另一只眼睛
      ctx.arc(180, 150, 10, 0, Math.PI * 2, false);
      ctx.stroke();
      //   画嘴巴
      ctx.beginPath();
      ctx.arc(120, 200, 50, 0, Math.PI, false);
      ctx.stroke();
    </script>
  </body>
</html>
